package cn.wxq.daily.empdailymgforserve.service.impl;

import cn.wxq.daily.empdailymgforserve.domain.Vacation;
import cn.wxq.daily.empdailymgforserve.domain.VacationAudit;
import cn.wxq.daily.empdailymgforserve.mapper.VacationAuditDao;
import cn.wxq.daily.empdailymgforserve.service.VacationAuditService;
import cn.wxq.daily.empdailymgforserve.service.VacationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 出勤休假审批
 */
@Service
public class VacationAuditServiceImpl implements VacationAuditService {
    @Autowired
    private VacationAuditDao vacationAuditDao;

    @Autowired
    private VacationService vacationService;

    /**
     * 请假或者加班审核
     * @param vacationAudit
     * @return
     */
    @Override
    public int insertAuditInfo(VacationAudit vacationAudit) {
        //关联薪资表

        //设置审核状态
        Vacation vacation = new Vacation();
        vacation.setLeaveId(vacationAudit.getLeaveId());
        vacation.setStatus("1");//已审核完成
        int goStatus = vacationService.updateVacation(vacation);
        if (goStatus >0){
            vacationAudit.setAuditTime(new Date());
            int row = vacationAuditDao.insertAuditInfo(vacationAudit);
            return  row;
        }else {
            return 0;
        }

    }

    /**
     * 出差审核（针对薪资关联不同）
     * @param vacationAudit
     * @return
     */
    @Override
    public int insertAuditBusiness(VacationAudit vacationAudit) {
        //设置审核状态
        Vacation vacation = new Vacation();
        vacation.setLeaveId(vacationAudit.getLeaveId());
        vacation.setStatus("1");//已审核完成
        int goStatus = vacationService.updateVacation(vacation);
        if (goStatus >0){
            vacationAudit.setAuditTime(new Date());
            int row = vacationAuditDao.insertAuditInfo(vacationAudit);
            return  row;
        }else {
            return -1;
        }

    }
}
